package com.ly.mp.dal.comm.mybatis;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

@Configuration
@AutoConfigureBefore({MybatisPlusConfiguration.class})
public class MybatisInterceptor {
//    @Bean
//    @ConditionalOnMissingBean
//    public PerformanceInterceptor performanceInterceptor() {
//        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
//        performanceInterceptor.setWriteInLog(true);
//        performanceInterceptor.setFormat(true);
//        performanceInterceptor.setMaxTime(5000L);
//        return performanceInterceptor;
//    }

//    @Bean
//    @ConditionalOnMissingBean
//    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
//        return new OptimisticLockerInterceptor();
//    }
    
//    @Bean
//    @ConditionalOnMissingBean
//    public PaginationInterceptor paginationInterceptor(DataSourceInfo info) {
//        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//        if (info != null && info.getUrl().contains("jdbc:jtds:sqlserver")) {
//            paginationInterceptor.setDialectType("sqlserver");
//        }
//
//        return paginationInterceptor;
//    }
    
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        // 乐观锁
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        // 添加自动分页插件 PaginationInnerInterceptor
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        // 添加ID生成器拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return mybatisPlusInterceptor;
    }


}